package com.hx.entity;


import com.hx.service.CallService;
import com.hx.service.NetService;
import com.hx.service.SendService;

import java.io.Serializable;
import java.util.*;
public class SuperPackage extends ServicePackage implements NetService, SendService, CallService , Serializable {
   private int talkTime;
    private int smsCount;
    private int flow;
    private  double price;
    public SuperPackage() {
        super(78,"超人套餐");
        this.talkTime = 200;
        this.smsCount = 50;
        this.flow = 1;
        this.price=78;
    }
    public int getTalkTime() {
        return talkTime;
    }

    public void setTalkTime(int talkTime) {
        this.talkTime = talkTime;
    }

    public int getSmsCount() {
        return smsCount;
    }

    public void setSmsCount(int smsCount) {
        this.smsCount = smsCount;
    }

    public int getFlow() {
        return flow;
    }

    public void setFlow(int flow) {
        this.flow = flow;
    }

    @Override
    public double getPrice() {
        return price;
    }

    @Override
    public void setPrice(double price) {
        this.price = price;
    }

    public void showInft() {
        System.out.println("超人套餐：通话时长为"+this.getTalkTime()+"分钟/月,"
                + "短信条数为"+this.getSmsCount()+"条/月,上网流量为"
                +this.getFlow()+"GB/月,资费"+this.getPrice()+"/月。");
    }

     public int call(int minCount, MobileCard card) {
         int temp = minCount;
         for(int i = 0; i < minCount; i++){
             if(this.talkTime - card.getConsumAmont() >= 1){
                 //第一种情况：套餐剩余通话时长可以支持1分钟通话
                 card.setConsumAmont(card.getRealTalkTime() + 1);
             }else if(card.getMonery() >= 0.2){
                 //第二种情况：套餐通话时长已用完，账户余额可以支付1分钟通话，使用账户余额支付
                 card.setConsumAmont(card.getRealTalkTime() + 1); //实际使用通话时长1分钟
                 //账户余额消费0.2元（1分钟 额外通话）
                 card.setMonery(card.getMonery() - 0.2);
                 card.setConsumAmont(card.getConsumAmont() + 0.2);  //当月消费金额 + 0.2
             }else{
                 temp = i; //记录实际通话分钟数
                 try {
                     throw new Exception("本次已经通话" + i + "分钟，您的余额不足，请充值后再使用！");
                 } catch (Exception e) {
                     e.printStackTrace();
                 }

             }
         }
         return temp;

    }
       public int  send(int count, MobileCard card) {
           int temp = count;
           for(int i = 0; i < count; i++){
               if(this.smsCount - card.getRealSMSCount() >= 1){
                   //第一种情况：套餐剩余短信数能够发送一个短信
                   card.setRealSMSCount(card.getRealSMSCount() + 1);
               }else if(card.getMonery()>= 0.1){
                   //第二种情况：套餐内短信已经用完，剩下话费能够允许发一条短信
                   card.setRealSMSCount(card.getRealSMSCount() + 1); //实际短信数加 1 条
                   //账户余额消费0.1元，（一条短信）
                   card.setMonery(card.getMonery()- 0.1);
                   card.setConsumAmont(card.getConsumAmont() + 0.1);  //当月消费金额 + 0.1
               }else{
                   temp = i; //记录发短信条数
                   try {
                       throw new Exception("短信已经发送" + i + "条，您的余额不足，请充值后再使用！");
                   } catch (Exception e) {
                       e.printStackTrace();
                   }
               }
           }
           return temp;



    }

       public int  netPlay(int flow, MobileCard card) {
           int temp = flow;
           for(int i = 0; i < flow; i++){
               if(this.flow - card.getRealFlow() >= 1){
                   //第一种情况：流量剩余够 1 MB
                   card.setRealFlow(card.getRealFlow() + 1);
               }else if(card.getMonery() >= 0.1){
                   //第二种情况：套餐内流量已经用完，剩下话费够支付 1 MB的流量
                   card.setRealFlow(card.getRealFlow() + 1); //实际短信数加 1 条
                   //账户余额消费0.1元，（1MB流量）
                   card.setMonery(card.getMonery() - 0.1);
                   card.setConsumAmont(card.getConsumAmont() + 0.1);  //当月消费金额 + 0.1
               }else{
                   temp = i; //记录使用流量多少MB
                   try {
                       throw new Exception("流量已经使用" + i + "MB，您的余额不足，请充值后再使用！");
                   } catch (Exception e) {
                       e.printStackTrace();
                   }
               }
           }
           return temp;

    }

}